<?php

namespace admin\models;

use ijony\helpers\Utils;
use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "{{%timeline}}".
 *
 * @property string $id 事记 ID
 * @property string $case_id 案例 ID
 * @property string $name 标题
 * @property string $content 内容
 * @property int $created_at 创建时间
 * @property int $updated_at 修改时间
 * @property int $status 状态
 *
 * @property Cases $case
 */
class Timeline extends \common\models\Timeline
{

    public function behaviors()
    {
        return [
            TimestampBehavior::className(),
        ];
    }

    public function getCase()
    {
        return $this->hasOne(Cases::className(), ['id' => 'case_id']);
    }

    public function getCaseSelectData()
    {
        return Cases::find()->select('name')->where(['status' => Cases::STATUS_ACTIVE])->indexBy('id')->column();
    }

    public function getStatus()
    {
        $datas = $this->getStatusSelectData();

        return isset($datas[$this->status]) ? $datas[$this->status] : '';
    }

    public function getStatusLabel()
    {
        if($this->status == self::STATUS_ACTIVE){
            $class = 'label-primary';
        }else{
            $class = 'label-danger';
        }

        return Utils::label($this->getStatus(), $class);
    }

    public function getStatusSelectData()
    {
        return [
            self::STATUS_UNACTIVE => '禁用',
            self::STATUS_ACTIVE => '启用',
        ];
    }
}
